<?php
class BasicController extends Controller {
	
	//机构管理(编辑、增加下级机构、删除)
	function AgencyAction(){
		$p['agency'] = $this->user["agency_id"];
		$this->JS['Agency']= CommonModel::getInstance()->getAgencyCombox($p);
		$this->view("basic.agency","item");
	}
	
	//取得常来
	function CostAction(){
		$rs = ConstModel::getInstance()->ConstGroupValue();
		$this->json->toJson($rs[5]);
	}
	
	//机构管理(编辑画面)
	function AgencyEditAction(){
		
		$this->view("basic.agency.edit","item");
	}
	
	// 增加修改机构
	function AgencyAddAction(){
		$p['types'] = PA(P("data",array()),"types","");
		$p['id'] = PA(P("data",array()),"id","");
		$p['business'] = PA(P("data",array()),"business","");
		$p['name'] = PA(P("data",array()),"name","");
		$p['addres'] = PA(P("data",array()),"addres","");
		$p['contact'] = PA(P("data",array()),"contact","");
		$p['tel'] = PA(P("data",array()),"tel","");
		$p['desc'] = PA(P("data",array()),"desc","");
		$p['status'] = PA(P("data",array()),"status","否");
		if($p['types'] == "new"){
			AgencyModel::getInstance()->AgencyAdd($p);
		}else{
			AgencyModel::getInstance()->AgencyUpd($p);
		}
	}
	
	// 删除机构
	function AgencyDelAction(){
		$p['id'] = P("id","");
		$count = AgencyModel::getInstance()->AgencyCount($p);
		if($count == 0){
			AgencyModel::getInstance()->AgencyDel($p);
			$this->json->code("OK")->out();
		}else{
			$this->json->code("GO")->out();
		}
	}
	
	// 删除部门
	function PositionDelAction(){
		$p['id'] = P("id","");
		PositionModel::getInstance()->PositionDel($p);
	}
	
	// 修改部门
	function PositionUpdAction(){
		$p['id'] = PA(P("data",array()),"id","0");
		$p['name'] = PA(P("data",array()),"name","");
		$p['desc'] = PA(P("data",array()),"desc","");
		$p['agency'] = G("agency","0");
		if($p['id']==0){
			PositionModel::getInstance()->PositionAdd($p);
		}else{
			PositionModel::getInstance()->PositionUpd($p);
		}
	}
	
	// 删除区域
	function AreaDelAction(){
		$p['id'] = P("id","");
		AreaModel::getInstance()->AreaDel($p);
		$this->json->code("OK")->out();
	}
	
	// 区域(编辑画面)
	function AreaEditAction(){
		$this->view("basic.area.edit","item");
	}
	
	// 增加修改区域
	function AreaAddAction(){
		$p['types'] = PA(P("data",array()),"types","");
		$p['id'] = PA(P("data",array()),"id","");
		$p['name'] = PA(P("data",array()),"name","");
		if($p['types'] == "new"){
			AreaModel::getInstance()->AreaAdd($p);
		}else{
			AreaModel::getInstance()->AreaUpd($p);
		}
	}
	
	// 常规选项
	function ConstAction(){
		$this->view("basic.const","item");
	}
	
	// 常规选项(组)
	function ConstGroupAction(){
		$this->json->toJson(ConstModel::getInstance()->ConstGroup());
	}
	
	// 常规选项(值)
	function ConstValueAction(){
		$p['gid'] = P("gid","0");
		$this->json->toJson(ConstModel::getInstance()->ConstValue($p));
	}
	
	// 常规选项(修改、增加)
	function ConstUpdAction(){
		$p['gid'] = G("gid","0");
		$p['id'] = PA(P("data",array()),"id","0");
		$p['val'] = PA(P("data",array()),"val","0");
		$p['name'] = PA(P("data",array()),"name","");
		if($p['id'] == 0){
			ConstModel::getInstance()->ConstValueAdd($p);
		}else{
			ConstModel::getInstance()->ConstValueUpd($p);
		}
	}
	
	// 常规选项(删除)
	function ConstDelAction(){
		$p['id'] = P("id","");
		ConstModel::getInstance()->ConstValueDel($p);
	}
	
	// 派工配件管理
	function DeviceAction(){
		$this->view("basic.device","item");
	}
	
	// 派工配件数据
	function DeviceListAction(){
		$p["p"] = P("pageIndex",0);
		$p["r"] = P("pageSize",15);
		$p["name"] = P("name","");
		$p["brand"] = P("brand","");
		$p["pattern"] = P("pattern","");
		$p["sortField"] = P("sortField","id");
		$p["sortOrder"] = P("sortOrder","asc");
		$data = DeviceModel::getInstance()->getDevice($p);
		$this->json->toJson(array("total"=>DeviceModel::getInstance()->getCount($p),"data"=>$data));
	}
	
	// 派工配件(修改、增加)
	function DeviceUpdAction(){
		$p['id'] = PA(P("data",array()),"id","0");
		$p['name'] = PA(P("data",array()),"name","");
		$p['types'] = PA(P("data",array()),"types","");
		$p['brand'] = PA(P("data",array()),"brand","");
		$p['pattern'] = PA(P("data",array()),"pattern","");
		$p['remark'] = PA(P("data",array()),"remark","");
		if($p['id'] == 0){
			DeviceModel::getInstance()->DeviceAdd($p);
		}else{
			DeviceModel::getInstance()->DeviceUpd($p);
		}
	}
	
	// 派工配件(删除)
	function DeviceDelAction(){
		$p['id'] = P("id","0");
		DeviceModel::getInstance()->DeviceDel($p);
	}
}